import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/assets_tool/app_colors.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_page/mine_business/make_money/withdrawal_page.dart';
import 'package:tiktokadult/hj_page/mine_business/welfare/share_data_list_page.dart';
import 'package:tiktokadult/hj_page/mine_business/widgets/mine_share_qr_view.dart';
import 'package:tiktokadult/routers/jump_router.dart';
import 'package:tiktokadult/tools_base/global_store/store.dart';
import 'package:tiktokadult/tools_base/widget/net_image_widget.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';
import 'package:provider/provider.dart';

import '../../../config/config.dart';

class MineIncomePage extends StatefulWidget {
  const MineIncomePage({super.key});

  @override
  State<MineIncomePage> createState() => _MineIncomePageState();
}

class _MineIncomePageState extends State<MineIncomePage> {
  @override
  void initState() {
    super.initState();
    globalStore.refreshWallet();
  }

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      child: Column(
        children: [
          Column(
            children: [
              Container(
                padding: EdgeInsets.only(left: 16, right: 16, top:6),
                decoration: BoxDecoration(
                  image: DecorationImage(
                    image: AssetImage("assets/images/hj_mine/Income_header_bg.webp"),
                    fit: BoxFit.cover,
                  ),
                ),
                child: Column(
                  children: [
                    Consumer<GlobalStore>(
                      builder: (_, store, __) => Row(
                        children: [
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(color: Color(0xFFFDB43D), width: 1),
                              borderRadius: BorderRadius.circular(30),
                            ),
                            child: NetworkImageLoader(
                              imageUrl: store.meInfo?.portrait ?? '',
                              width: 60,
                              height: 60,
                              borderRadius: 30,
                            ),
                          ),
                          10.sizeBoxW,
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                "普通代理",
                                style: const TextStyle(color: const Color(0xFFFFFFFF), fontWeight: FontWeight.w500, fontSize: 18.0),
                              ),
                              5.sizeBoxH,
                              Text(
                                "邀请好友快速提现",
                                style: const TextStyle(color: const Color(0xff989898), fontWeight: FontWeight.w400, fontSize: 12.0),
                              )
                            ],
                          ),
                          Spacer(),
                          Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Text(
                                "可提现金额",
                                style: const TextStyle(color: const Color(0xB2FFFFFF), fontWeight: FontWeight.w500, fontSize: 12.0),
                              ),
                              SizedBox(height: 1),
                              Text(
                                "${(store.wallet?.income ?? 0) ~/ 10}",
                                style: const TextStyle(color: const Color(0xffFDB43D), fontWeight: FontWeight.w400, fontSize: 28.0),
                              )
                            ],
                          )
                        ],
                      ),
                    ),
                    29.sizeBoxH,
                    Container(
                      padding: EdgeInsets.symmetric(horizontal: 10),
                      width: double.infinity,
                      child: Row(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          InkWell(
                            onTap: () => Get.to(WithdrawalPage()),
                            child: Image.asset(
                              'assets/images/hj_mine/withdraw_now.webp',
                              width: (MediaQuery.of(context).size.width - 70) / 2,
                              height: 48,
                            ),
                          ),
                          InkWell(
                            onTap: () => Get.to(ShareDataListPage()),
                            child: Image.asset(
                              'assets/images/hj_mine/promotional_data.webp',
                              width: (MediaQuery.of(context).size.width - 70) / 2,
                              height: 48,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              if (Config.proxyBannerJump != null)
                Padding(
                  padding: const EdgeInsets.only(left: 16, right: 16),
                  child: Column(
                    children: [
                      24.sizeBoxH,
                      InkWell(
                        onTap: () {
                          pushToPageByLink(Config.proxyBannerJump?.additionalProp?.url ?? "");
                          //
                        },
                        child: Image.asset(
                          'assets/images/hj_mine/proxy_banner.webp',
                          width: double.infinity,
                        ),
                      ),
                    ],
                  ),
                )
            ],
          ),
          12.sizeBoxH,
          Container(
            padding: EdgeInsets.symmetric(horizontal: 16, vertical: 5),
            child: Row(
              children: [
                Text(
                  "规则说明",
                  style: const TextStyle(color: const Color(0xFFFFFFFF), fontWeight: FontWeight.w600, fontSize: 18.0),
                ),
              ],
            ),
          ),
          Container(
            padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
            width: double.infinity,
            child: RichText(
              textAlign: TextAlign.left,
              text: TextSpan(
                style: TextStyle(fontSize: 12, color: Color(0xFF989898)), // 默认样式
                children: [
                  // 1、邀请好友注册成功即可获得会员和大量积分。
      // 积分可兑换会员、观看视频等等
                  TextSpan(text: '1. 邀请'),
                  TextSpan(
                    text: '好友注册成功',
                    style: TextStyle(color: AppColors.actionRed),
                  ),
                  TextSpan(text: '即可获得'),
                  TextSpan(
                    text: '会员',
                    style: TextStyle(color: AppColors.actionRed),
                  ),
                  TextSpan(text: '和大量'),
                  TextSpan(
                    text: '积分',
                    style: TextStyle(color: AppColors.actionRed),
                  ),
                  TextSpan(text: '。\n'),
                  TextSpan(text: '积分可兑换'),
                  TextSpan(
                    text: '会员',
                    style: TextStyle(color: AppColors.actionRed),
                  ),
                  TextSpan(text: '、观看视频等等'),
                ],
              ),
            ),
          ),
          Container(
            padding: EdgeInsets.symmetric(vertical: 5, horizontal: 16),
            width: double.infinity,
            child: RichText(
              textAlign: TextAlign.left,
              text: TextSpan(
                style: TextStyle(fontSize: 12, color: Color(0xFF989898)), // 默认样式
                children: [
                  TextSpan(text: '2．邀请说明：点击【保存二维码】或【复制推广链接】。获取专属推广链接，推荐分享给其他人下载即可。'),
                ],
              ),
            ),
          ), 
          18.sizeBoxH,
          MineShareQRView(),
          12.sizeBoxH,
          Container(
            padding: const EdgeInsets.only(left: 16, right: 16),
            color: Color(0x0DFFFFFF),
            child: Image.asset(
              "invite_steps.webp".mineImgPath,
              fit: BoxFit.fill,
            ),
          ),
          24.sizeBoxH,
        ],
      ),
    );
  }
}
